// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import VueQuillEditor from 'vue-quill-editor'
import VueClipboard from 'vue-clipboard2'
import echarts from 'echarts'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
import 'element-ui/lib/theme-chalk/index.css';
import store from './store'
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(VueClipboard)

Vue.use(VueQuillEditor)
/* eslint-disable no-new */
Vue.prototype.$echarts = echarts;

router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title}`;
  const role = localStorage.getItem('admin');
  // const val = JSON.parse(role)
  const val = eval("(" + role + ")")
  if (val !== null) {
    const timeSpan = Date.now() - val.time;

    if (timeSpan > val.expire) {
      localStorage.removeItem("admin");
      next('/login')
      return null;
    }

  }

  if (!val && to.path !== '/login') {
    next('/login')
  } else if (to.meta.permission) {//如果有权限的页面才能访问
    val.value === "admin" ? next() : next('/403')
  } else {
    //判断浏览器是否支持富文本编辑器
    if (navigator.userAgent.indexOf('MISE') > -1 && to.path === "/edit") {
      alert("不支持")
    } else {
      next()
    }

  }
})

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
